package com.sskj.api.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sskj.api.domain.Position;
import com.sskj.api.service.IPositionService;
import com.sskj.api.vo.req.PositionPageListReq;
import com.sskj.common.util.ApiResponseUtil;
import com.sskj.common.vo.ApiResponse;
import com.sskj.common.vo.SimplePagination;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "岗位模块")
@RestController
@RequestMapping("/admin/position")
@Validated
public class PositionController {

    @Autowired
    private IPositionService positionService;

    @Operation(summary = "新增岗位")
    @PostMapping("add")
    public ApiResponse<Object> add(@Valid @RequestBody Position position) {
        positionService.add(position);

        return ApiResponseUtil.success();
    }

    @Operation(summary = "删除岗位")
    @PostMapping("delete")
    public ApiResponse<Object> delete(@RequestParam Long id) {
        positionService.deleteById(id);

        return ApiResponseUtil.success();
    }

    @Operation(summary = "更新岗位")
    @PostMapping("update")
    public ApiResponse<Object> update(@Valid @RequestBody Position position) {
        positionService.update(position);

        return ApiResponseUtil.success();
    }

    @Operation(summary = "分页列表")
    @GetMapping("pageList")
    public ApiResponse<SimplePagination<Position>> pageList(PositionPageListReq req) {
        IPage<Position> positionIPage = positionService.pageList(req);

        return ApiResponseUtil.success(positionIPage);
    }
}
